@extends('layouts.admin')

@section('content')

<div class="row">
    <div class="col-md-offset-1 col-md-10">
        <h1>weibo</h1>
        <table class="table table-hover">
                <thead>
                <tr>
                    <th>作者</th>
                    <th>内容</th>
                    <th>媒体</th>
                    <th>type</th>
                    <th>更新时间</th>
                    <th><span class="glyphicon glyphicon-edit"></span></th>
                </tr>
            </thead>
                 <tbody>

                @foreach($weibos as $w)
                    <tr>
                        <td>
                            <img src="{{$w->avatar}}" width="50" height="50" alt="{{$w->weibor}}">
                            <span>{{$w->weibor}}</span>
                        </td>
                        <td>
                            {{$w->body}}
                        </td>
                        <td>
                            <a href="{{$w->media_url}}"> {{$w->media_url}}</a>
                        </td>
                        <td>{{$w->media_type}}</td>
                        <td>{{$w->updated_at->diffForHumans()}}</td>
                        <td>
                            @if($w->type === 'favorate')
                            <a data-url="{{url('weibo/isTrash',$w)}}" class="ajax-get">取消收藏</a>
                            @else
                            <a data-url="{{url('weibo/isValue',$w)}}" class="ajax-get">收藏</a>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        {!! $weibos->render() !!}
    </div>
</div>

@endsection

@section('scripts')
    <script>

        $(function(){
            $('.ajax-get').click(function(){
                var  that = $(this);
                var url = that.data('url');
                $.get(url,function(data,status){
                    if(status === 'success') {
                        var text = that.text() === '收藏' ? '取消收藏':'收藏';
                        that.text(text);
                    }







                })







            })
        });




    </script>


@endsection
